﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>

void compare(char ch1[], char ch2[], int len1, int len2)
{
	if (len1 != len2)
	{
		printf("不构成左旋关系。\n");
	}
	else
	{
		int k = len1;
		if (strcmp(ch1, ch2))
		{
			printf("构成左旋关系。\n");
		}
		while (k > 0)
		{
			
			int i = 0;
			char t = ch1[i];
			for (i = 0; i < len1 - 1; i++)
			{
				ch1[i] = ch1[i + 1];
			}
			ch1[i] = t;
			k--;
			if (strcmp(ch1, ch2))
			{
				printf("构成左旋关系。\n");
				break;
			}
		}
	}
}

int main()
{
	char s1[] = "ABCDD";
	int len1 = strlen(s1);
	char s2[] = "CDDAB";
	int len2 = strlen(s2);
	char s3[] = "abcd";
	int len3 = strlen(s3);
	compare(s1, s2, len1, len2);
	compare(s1, s3, len1, len3);

	return 0;
}